| API Documentation |  |

- MAIN PAGE
- NAMESPACES
- CLASSES

Public Member Functions | List of all members
nkTasks::ThreadPool Class Referencefinal

A pool with pre-created threads, allowing to queue work asynchronously. More...

## Public Member Functions
| ThreadPool (unsigned int threadCount=0) noexcept
| ~ThreadPool ()
unsigned int | getThreadCount () const
Thread * | getThread (unsigned int index) const
void | addTask (nkMemory::UniquePtr< Task > task)
void | cancelPendingTasks ()
void | flush ()
void | resizeForThreadCount (unsigned int threadCount)

## Detailed Description

A pool with pre-created threads, allowing to queue work asynchronously.

## Constructor & Destructor Documentation

## ◆ ThreadPool()

nkTasks::ThreadPool::ThreadPool | ( | unsigned int | threadCount = `0` | ) |
| noexcept

Constructor.

Parameters

  threadCount | The number of threads the pool should prepare.

## ◆ ~ThreadPool()

nkTasks::ThreadPool::~ThreadPool | ( |  | ) |

Destructor.

Remarks
  The destructor will automatically cancel any pending task and join with all its thread. If pending work has to be processed before, it is required to manually join before destructing the pool.

## Member Function Documentation

## ◆ getThreadCount()

unsigned int nkTasks::ThreadPool::getThreadCount | ( |  | ) | const

Returns
  The number of threads contained in the pool.

## ◆ getThread()

Thread* nkTasks::ThreadPool::getThread | ( | unsigned int | index | ) | const

Parameters

  index | The index of the thread to retrieve, within the pool.

Returns
  The thread attached to the index requested if available, nullptr otherwise.

## ◆ addTask()

void nkTasks::ThreadPool::addTask | ( | nkMemory::UniquePtr< Task > | task | ) |

Add a task to be pooled.

Parameters

  task | The task to be processed.

Remarks
  The task will be processed asynchronously when a thread becomes available for it. As such, it is possible it is queued while past tasks are being processed, before getting assigned to a thread.

## ◆ cancelPendingTasks()

void nkTasks::ThreadPool::cancelPendingTasks | ( |  | ) |

Cancels all the tasks queued, waiting to be picked by a thread from the pool.

## ◆ flush()

void nkTasks::ThreadPool::flush | ( |  | ) |

Flushes all pending work and only returns once the pool has processed everything.

## ◆ resizeForThreadCount()

void nkTasks::ThreadPool::resizeForThreadCount | ( | unsigned int | threadCount | ) |

Resizes the pool with a different amount of threads.

Parameters

  threadCount | The number of threads the pool should feature.

The documentation for this class was generated from the following file:

- Documentation/Headers/NilkinsTasks/Threads/ThreadPool.h